package com.example.exam.config;

import com.example.exam.filter.LoginFilter;
import com.example.exam.filter.ManagementFilter;
import com.example.exam.service.ManagementUserService;
import com.example.exam.service.RedisService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zhozixiong
 * @date 2023/03/08
 */
@Configuration
@RequiredArgsConstructor
public class LoginConfig implements WebMvcConfigurer {

    private final RedisService redisService;
    private final ManagementUserService managementUserService;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginFilter(redisService))
                //需要过滤的路径
                .addPathPatterns("/**")
                //不需要过滤的路径
                .excludePathPatterns("/management/**", "/getPicture/*", "/test");
        registry.addInterceptor(new ManagementFilter(managementUserService))
                .addPathPatterns("/management/**")
                .excludePathPatterns("/management/login");
    }
}
